TOOL.Category = "NPC Control - Actors"
TOOL.Name = "Spawning"
TOOL.Command = nil
TOOL.ConfigName = ""

TOOL.ClientConVar["npctospawn"] = "models/gman_high.mdl"

local menustatus = 0 //Closed
local selectednpc = nil

//SpawnList
list.Set("SpawnableActors", "models/gman_high.mdl", {})
for i=1, 3, 1 do
  for k=1, 7, 1 do
    if (k != 5) then list.Set("SpawnableActors", "models/humans/group0" .. tostring(i) .. "/female_0" .. tostring(k) .. ".mdl", {}) end
  end
end
for i=1, 3, 1 do
  for k=1, 9, 1 do
    list.Set("SpawnableActors", "models/humans/group0" .. tostring(i) .. "/male_0" .. tostring(k) .. ".mdl", {})
  end
end
//If you want me to add one, contact me at benjy355@gmail.com
list.Set("SpawnableActors", "models/combine_soldier.mdl", {})
list.Set("SpawnableActors", "models/combine_super_soldier.mdl", {})
list.Set("SpawnableActors", "models/combine_soldier_prisonguard.mdl", {})
list.Set("SpawnableActors", "models/alyx_ep2.mdl", {})
list.Set("SpawnableActors", "models/barney.mdl", {})
list.Set("SpawnableActors", "models/vortigaunt.mdl", {})
list.Set("SpawnableActors", "models/vortigaunt_doctor.mdl", {})
list.Set("SpawnableActors", "models/vortigaunt_slave.mdl", {})


if CLIENT then
  language.Add( "Tool_npc_actor_spawn_name", "Actor Control: Spawning" )
  language.Add( "Tool_npc_actor_spawn_desc", "Make NPC actor's speak" )
  language.Add( "Tool_npc_actor_spawn_0", "Left-Click to spawn an actor, Right-Click to remove them" )
  language.Add( "Undone_actors", "Undone Actor" )
end

function TOOL:LeftClick( trace )
  if (trace.HitWorld && !trace.HitSky) then
    local newactor = ents.Create("cycler_actor")
    newactor:SetKeyValue("spawnflags", "25108")
    newactor:SetKeyValue("model", self:GetClientInfo("npctospawn"))
    newactor:SetPos(trace.HitPos)
    newactor:Spawn()
    undo.Create("actors")
      undo.AddEntity(newactor)
      undo.SetPlayer(self:GetOwner())
    undo.Finish()
    return true
  end
end

function TOOL:RightClick( trace )
  if (trace.Entity:IsValid() && trace.Entity:IsNPC() && trace.Entity:GetClass() == "cycler_actor") then
    trace.Entity:Remove()
    return true
  end
end

function TOOL.BuildCPanel(panel)
  local data = {}
  data.Label = "Actor to Spawn"
  data.ConVar = "npc_actor_spawn_npctospawn"
  data.Category = "Actors"
  data.Models = list.Get( "SpawnableActors" )
  panel:AddControl("PropSelect", data)
end